import React, {Component } from "react";
import Qs from 'qs'
import axios from "../../../../http";
import {List,SearchBar, NavBar} from "antd-mobile";
import {withRouter} from "react-router";
import {PRIVATE_ROUTE} from "../../../../route.constants";
 class UserScheduleToMe extends Component {
    constructor(props){
        super(props)
        this.state={userList:[],hasMore:true,searchBarValue:'',};
      }
      loadUserData=(likeName)=>{
        axios.post('api/oa/settings/user/relationship/findByPage', Qs.stringify({
            page: 0,
            size: 100,
            name:likeName,
            type:'WORK_REPORT'
        }),{headers: {'Content-Type': 'application/x-www-form-urlencoded'}})
            .then((response)=>{
                let  dataList=response.data.data.content;
                let  convertedDataList=new Array();

                for(let i=0;i<dataList.length;i++){
                    convertedDataList.push(dataList[i]["userFrom"]);
                }
                this.setState({userList:convertedDataList});
            })
            .catch(function (error) {

            });
    }
    onChange=(val)=>{
        console.log(val)
        let state={
          id:val.id,
          realName:val.realName,
          prePage:'/main/'+PRIVATE_ROUTE.APP_OA_WORK_REPORT_USER_TO_ME
        }
        
        this.props.history.push({ pathname: "/main/"+PRIVATE_ROUTE.APP_OA_WORK_SCHEDULE_USER_DETAIL, state: state });
    }
    componentDidMount() {
        this.loadUserData('')
    }


    searchBarOnChange=(val: string)=>{
        this.setState({searchBarValue:val});
        this.loadUserData(val);
    }

    goBack=()=>{
        
        this.props.history.push({ pathname: "/"})
    }



    render() {
        return (
          <>
          <NavBar onBack={this.goBack}>请选择用户</NavBar>
          <SearchBar  placeholder="输入姓名搜索" onChange={this.searchBarOnChange}/>
          <List title='可点击列表'   >
              {this.state.userList.map((item, index) => (
                  //  <CheckList.Item value={item.realName+'_'+item.id}>{item.name+'('+item.realName+')'}</CheckList.Item>
                  <List.Item  key={item.id} onClick={e=>this.onChange({realName:item.realName,id:item.id})}>{item.name+'('+item.realName+')'}</List.Item>
              ))}
          </List>
        </>
          )
    }
}
export default withRouter(UserScheduleToMe)